import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout布局页面 */
import employees from './modules/employees'
import departments from './modules/departments'
import setting from './modules/setting'
import salarys from './modules/salarys'
import social from './modules/social'
import attendances from './modules/attendances'
import approvals from './modules/approvals'
import permission from './modules/permission'
console.log('123')
// 静态路由规则
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: () => import('@/layout'),
    redirect: '/dashboard',
    beforeEnter: (to, from, next) => {
      next()
    },
    children: [{
      path: '', // 二级路由path什么都不写 表示二级默认路由
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard首页', icon: 'dashboard' }
    },
    {
      // excel文件导入 的路由
      path: '/import',
      component: () => import('@/views/import'),
      hidden: true // 隐藏在左侧菜单中
    },
    {
      path: '/404', component: () => import('@/views/404.vue')
      // * 必须放在最后，/404可以不放在最后
    }
    ]
  },
  
  // // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]
// 导出动态路由给权限管理：
export const asyncrouter = [departments, employees, setting, salarys, social, attendances, approvals, permission]
// 创建路由实例
const createRouter = () => new Router({
  // base: 'baidu/',  //加一个自定义基地址
  mode: 'history', // 需要服务器支持
  scrollBehavior: () => ({ y: 0 }), // 管理滚动行为 如果出现滚动 切换就让页面回到顶部
  // routes: [...constantRoutes, ...asyncrouter] // 临时合并
  // 简易权限管理-->初始化只加载静态路由
  routes: [...constantRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router 重置路由，退出登录使用
}

export default router
